﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace EditTable
{
    public class NorthWindClass
    {
        static NorthWindDataContext context = new NorthWindDataContext();

        public static List<Category> GetCategorres()
        {
            List<Category> categories = new List<Category>();
            categories = (from category in context.Categories
                                select category).ToList();
            return categories;            
        }

        public static void AddCategory(Category category)
        {
            context.Categories.InsertOnSubmit(category);
            context.SubmitChanges();
        }

        public static Category GetCategoryByID(int id)
        {
            var category = (from cat in context.Categories
                           where cat.CategoryID == id
                           select cat).FirstOrDefault();
            return category;
        }

        public static void Submit()
        {
            context.SubmitChanges();
        }

        public static void DeleteCategoryByID(int id)
        {            
            var category = (from cat in context.Categories
                            where cat.CategoryID == id
                            select cat).FirstOrDefault();
            context.Categories.DeleteOnSubmit(category);
            context.SubmitChanges();
        }
    }
}